package cn.dansj.common.utils.transfer;

import cn.dansj.common.utils.enums.OsType;

public abstract class OsUtils {
    public static boolean isWindows = currentOsType() == OsType.WINDOWS;
    public static boolean isLinux = currentOsType() == OsType.LINUX;
    public static boolean isMac = currentOsType() == OsType.MAC;
    public static boolean isUnix = currentOsType() == OsType.UNIX;
    public static boolean isSolaris = currentOsType() == OsType.SOLARIS;
    public static boolean isFreeBSD = currentOsType() == OsType.FREEBSD;
    public static boolean isOpenBSD = currentOsType() == OsType.OPENBSD;
    public static boolean isNetBSD = currentOsType() == OsType.NETBSD;
    public static boolean isSunOS = currentOsType() == OsType.SUNOS;
    public static boolean isAIX = currentOsType() == OsType.AIX;
    public static boolean isTypeUnix = isLinux || isMac || isUnix || isSolaris || isFreeBSD || isOpenBSD || isNetBSD || isSunOS || isAIX;

    public static OsType currentOsType() {
        String osName = System.getProperty("os.name").toLowerCase();
        if (osName.startsWith("windows")) {
            return OsType.WINDOWS;
        } else if (osName.startsWith("linux")) {
            return OsType.LINUX;
        } else if (osName.startsWith("mac")) {
            return OsType.MAC;
        } else if (osName.startsWith("unix")) {
            return OsType.UNIX;
        } else if (osName.startsWith("freebsd")) {
            return OsType.FREEBSD;
        } else if (osName.startsWith("openbsd")) {
            return OsType.OPENBSD;
        } else if (osName.startsWith("netbsd")) {
            return OsType.NETBSD;
        } else if (osName.startsWith("solaris")) {
            return OsType.SOLARIS;
        } else if (osName.startsWith("sunos")) {
            return OsType.SUNOS;
        } else if (osName.startsWith("aix")) {
            return OsType.AIX;
        } else {
            return OsType.NONE;
        }
    }
}
